package com.itboye.textileexpes.repository;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.reflect.TypeToken;
import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.CollectionCateTypeModel;
import com.itboye.textileexpes.beans.ColletionFenyeBeans;
import com.itboye.textileexpes.beans.GoodsBean;
import com.itboye.textileexpes.beans.OfferLineOrderBeans;
import com.itboye.textileexpes.interfaces.ICollocetion;
import com.itboye.textileexpes.json.ByJsonRequest.Builder;
import com.itboye.textileexpres.base.BaseErrorListener;
import com.itboye.textileexpres.base.BaseNetRepository;
import com.itboye.textileexpres.base.BaseSuccessReqListener;

public class CollectionRepository extends BaseNetRepository implements
		ICollocetion<ColletionFenyeBeans> {
	final static String QueryFenye = "By_Favorites_query";
	final static String DeleteCollect = "By_Favorites_bulkCancel";
	final static String TopCollect = "By_Favorites_stick";
	final static String CateTypeCollect = "By_Favorites_cate";
	final static String AddCollect = "By_Favorites_add";
	final static String OrderCollect = "By_IntentionalOrder_create";
	//首页不感兴趣
	final  static  String  Deltelike="By_Product_dislike";
	public CollectionRepository(ICompleteListener listener) {
		// TODO Auto-generated constructor stub
		super(listener);
	}

	@Override
	public void add(ColletionFenyeBeans model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "101";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("id", model.getIds());
		map.put("f_type", model.getFType());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(AddCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void delete(ColletionFenyeBeans model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("ids", model.getIds());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(DeleteCollect, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void update(ColletionFenyeBeans model) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("ids", model.getIds());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(TopCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void getInfo(ColletionFenyeBeans model) {

		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", model.getUid());
		map.put("p_ids", model.getFavorite_id());
		map.put("contact_name", model.getContact_name());
		map.put("note", model.getNote());

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(OrderCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public List<ColletionFenyeBeans> query(ColletionFenyeBeans model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void FenYeQuery(String uid, String page_size, String page_index,
			String keyword, String cate_id, String fav_type) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<ColletionFenyeBeans>() {
		}.getType();
		String apiVer = "101";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("keyword", keyword);
		map.put("cate_id", cate_id);
		map.put("uid", uid);
		map.put("page_size", page_size);
		map.put("page_index", page_index);
		map.put("fav_type", fav_type);

		(new Builder<ColletionFenyeBeans>())
				.setTypeVerParamsAndReturnClass(QueryFenye, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<ColletionFenyeBeans>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void CollectionCateType(String uid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<List<CollectionCateTypeModel>>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		(new Builder<List<CollectionCateTypeModel>>())
				.setTypeVerParamsAndReturnClass(CateTypeCollect, apiVer, map,
						type)
				.requestListener(
						new BaseSuccessReqListener<List<CollectionCateTypeModel>>(
								getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void CollectOrder(String uid, String pid) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("p_ids", pid);
		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(OrderCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void oncreate(String uid, String p_ids, String contact_name,
			String note) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("p_ids", p_ids);
		map.put("contact_name", contact_name);
		map.put("note", note);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(OrderCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void onDeleteShopcar(String uid, String id) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "100";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("id", id);
		

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(Deltelike, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

	@Override
	public void onAddLike(String uid, String id, String f_type) {
		// TODO Auto-generated method stub
		Type type = new TypeToken<String>() {
		}.getType();
		String apiVer = "101";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("uid", uid);
		map.put("id", id);
		map.put("f_type", f_type);

		(new Builder<String>())
				.setTypeVerParamsAndReturnClass(AddCollect, apiVer, map, type)
				.requestListener(
						new BaseSuccessReqListener<String>(getListener()))
				.errorListener(new BaseErrorListener(getListener()))
				.desEncodeThenBuildAndSend();
	}

}
